package com.qf.lanzhou.blog.api.controller.comment;

import com.qf.lanzhou.blog.api.controller.BaseServletPost;
import com.qf.lanzhou.blog.api.service.CommitReportCommentService;
import com.qf.lanzhou.blog.api.service.impl.CommitReportCommentServiceImpl;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebFilter;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 是柠檬甜
 * @ClassName CommentReportServlet
 * @description 评论举报功能
 * @date 2020/12/21 14:19
 * @modifier 是柠檬甜
 * @date 2020-12-21 14:19
 * @Version V1.0
 */
@WebServlet("/reportComment.do")
public class CommentReportServlet extends BaseServletPost {
    private CommitReportCommentService commentService = new CommitReportCommentServiceImpl();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String commentId = req.getParameter("commentId");
        long commentIdLong = Long.parseLong(commentId);
        String message = null;
        try {
            message = commentService.addAuditReportComment(commentIdLong);
            successResultWrite(message,resp);
        } catch (RuntimeException e) {
            String errorMessage = e.getMessage();
            failedResultWrite(errorMessage,resp);
        }
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
